package com.project.thisDatabase.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

import javax.annotation.Resource;

@ConditionalOnProperty(name = "spring.data.redis.listener", havingValue = "true")
@Configuration
public class RedisListenerConfig {

    @Resource
    private RedisTemplate<Object,Object> redisTemplate;

    @Bean
    RedisMessageListenerContainer container() {
        System.out.println("redis listener: default;");
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(redisTemplate.getConnectionFactory());
        return container;
    }

}
